<?php
	$_title='个人信息';
	include_once 'head.php';
	if($user_id==''){
		header('Location: login.php');
	}
	$userc=new user();

	//提交
	if($_POST['save']!=''){
		$arr=array(
			'self_intro'=>$_POST['self_intro'],'address'=>$_POST['address']
			);
		$res=$userc->userInfoUpdate($arr,'id="'.$user_id.'"');
		if($res==1){
			$msg='信息保存成功！';
		}else{
			$msg="信息保存失败！";
		}
		$url='user_basic_info.php';
		echo $commonc->submitAlert($msg,$url);
		exit();
	}

	//删除经历
	if($_GET['action']=='del'){
		$label=$_POST['label'];
		$id=$_POST['id'];
		$res=$userc->userExperienceDel($label,$id);
		echo $res;
		exit();
	}

	//添加-海外，工作、教育经历
	if($_GET['action']=='addExper'){
		$type=$_GET['type'];
		if($type=='oversea'){
			//海外
			$arr=array(
				'continent_id'=>$_POST['continent_id'],'country_id'=>$_POST['country_id']
				,'city'=>$_POST['city'],'school'=>$_POST['over_school']
				,'profession'=>$_POST['over_profession'],'entrance_time'=>strtotime($_POST['entrance_time'])
				,'granduate_time'=>strtotime($_POST['granduate_time']),'user_id'=>$user_id
				);
		}elseif ($type=='educate') {
			//教育
			$arr=array(
				'school'=>$_POST['school'],'user_id'=>$user_id,
				'profession'=>$_POST['profession']
				);
		}else{
			//工作
			$arr=array(
				'experience'=>$_POST['experience'],
				'position'=>$_POST['position'],
				'limit'=>$_POST['limit'],'user_id'=>$user_id
				);
		}
		$id=$userc->userExperienceInsert($type,$arr);
		if($id>0){
			if($type=='oversea'){
				//国家
				$html='<span class="j_bjzlnxny4 oversea"><span class="j_bjzlnxny41">洲际：'.$_POST['continent'].'&nbsp;国家：'.$_POST['country'].'&nbsp;城市：'.$_POST['city'].'&nbsp;学校：'.$_POST['over_school'].'&nbsp;专业：'.$_POST['over_profession'].'&nbsp;时间：'.$_POST['entrance_time'].'~'.$_POST['granduate_time'].'<a label="oversea" id="'.$id.'" class="del" href="javascript:;">×</a></span></span>';
			}elseif ($type=='educate') {
				$html='<span class="j_bjzlnxny4 educate"><span class="j_bjzlnxny41">学校：'.$_POST['school'].'&nbsp;专业：'.$_POST['profession'].'<a href="javascript:;" class="del" label="educate" id="'.$id.'">×</a></span></span>';
			}else{
				$html='<span class="j_bjzlnxny4 work"><span class="j_bjzlnxny41">工作（公司）：'.$_POST['experience'].'&nbsp;职位：'.$_POST['position'].'&nbsp;年限：'.$_POST['limit'].'<a label="work" class="del" id="'.$id.'" href="javascript:;">×</a></span></span>';
			}
		}
		$result=array('error'=>$id,'html'=>$html);
		echo json_encode($result);
		exit();
	}

	//会员基本信息
	$info=$userc->userInfo($user_id);
	$smarty->assign("info",$info);

	//工作经历
	$workList=$userc->userWorkList($user_id);
	$smarty->assign("workList",$workList['result']);

	//教育经理
	$educateList=$userc->userEducateList($user_id);
	$smarty->assign("educateList",$educateList['result']);

	//海外经历
	$overseaList=$userc->userOverseaList($user_id);
	$smarty->assign("overseaList",$overseaList['result']);

	//洲
	$continents=$userc->continentList(' order by id asc');
	$smarty->assign("continents",$continents['result']);

	//计算信息完整度
	$infoPercent=$userc->infoPercent;			//信息比例
	$percent=0;
	if(is_array($info)){
		foreach($info as $k=>$v){
			$percent+=$v!=''?$infoPercent[$k]:0;
		}
	}
	$percent+=$workList['result']!=''?$infoPercent['workList']:0;
	$percent+=$educateList['result']!=''?$infoPercent['educateList']:0;
	$percent+=$overseaList['result']!=''?$infoPercent['overseaList']:0;
	$percent=round(($percent/$infoPercent['total'])*100,1);
	$smarty->assign("percent",$percent);

	//html模板区分
	$html='user_basic_info.html';
	$smarty->display($html);		
?>